﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EzDesk.Apps.Data.ProjectModule;
using EzDesk.Apps.Model.ProjectModule;

namespace EzDesk.Apps.ServiceImpl.ProjectModule.History
{
    /// <summary>
    /// 管理项目历史的管理器
    /// </summary>
    public class HistoryManager
    {
        /// <summary>
        /// 创建新的项目历史
        /// </summary>
        public string CreateHistory(HistoryRecorderBase recorder)
        {
            // 用这个recorder创建项目历史
            return EzDeskProjectContainer.GoAndSave(
                container =>
                    {
                        var history = recorder.ProjectHistory;
                        container.ProjectHistorySet.AddObject(history);
                        return history.Content;
                    });
        }

        public List<ProjectHistory> Get(Guid projectId, int startIndex = 0, int count = 20)
        {
            return EzDeskProjectContainer.Go(
                container => container.ProjectHistorySet.Where(p => p.ProjectId == projectId)
                                 .OrderByDescending(p => p.CreateOn)
                                 .Skip(startIndex)
                                 .Take(count)
                                 .ToList());
        }

    }
}
